<?php
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$title='自助升级权限';
include_once './header.php';
if($conf['user_uppower_open']!=1)showmsg('错误', '授权平台未开放自助升级权限功能！', 4, './');
?>
<?php
if($userrow['power']==0){
    showmsg('警告', '对不起！您所在的用户组无法使用此功能！', 2, './');
}
if($userrow['power']==3){
    showmsg('警告', '小朋友，你已是最高权限，无需升级！', 2, './');
}
$program = $DB->get_row("select * from authguao_program where id='{$userrow['proid']}' limit 1");
if($program){
    $name=$program['name'];
}else{
    $name='未知程序';
}
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                自助升级权限
            </div>
            <div class="card-body">
                <div class="layui-elem-quote">权限越高，授权价格越低，添加代理价格也越低，全能管理员添加授权和代理皆是0成本</div>
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">升级权限：<span class="badge badge-danger-lighten">剩余不可提现余额：<?php echo round($userrow['rmb'],2)?>元</span></label>
                        <select name="power" class="form-control" lay-search lay-filter="power"><option value="-1">选择要升级的权限</option>
                        <?php if($userrow['power']==1){?>
                        <option value="2">超级管理员(<?php echo $name;?>)</option>
                        <?php }?>
                        <option value="3">代理商</option>
                        </select>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">升级价格：</label>
                        <input name="need" class="form-control" style="center;color:red;font-weight:bold" disabled>
                   </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_uppower">升 级</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form'], function () {
    var form = layui.form;
    form.on('select(power)', function(data){
        var power = data.value;
        var ii = layer.msg('正在获取价格中,请稍后...', {icon: 16, time: 10 * 1000});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=upcheck_money",
            data : {power:power},
            dataType: "json",
            success: function(data) {
                layer.close(ii);
                if (data.code == 0) {
                    $("input[name='need']").val(data.need+'元');
                } else {
                    $("input[name='need']").val("未知价格");
                }
            },
            error:function(data){
                layer.msg('服务器错误', {icon: 5});
                return false;
            }
        });
    });
    form.on('submit(submit_uppower)', function (data) {
        layer.alert('是否要执行当前操作？', {
            icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                uppower();
            }
        });
        return false;
    });
});
function uppower() {
    var power = $("select[name='power']").val();
    var ii = layer.msg('正在升级中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "POST",
        url: "ajax.php?act=uppower",
        data : {power:power},
        dataType: "json",
        success: function(data) {
            layer.close(ii);
            if (data.code == 0) {
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else if (data.code == 1) {
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.href = './';
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    });
    return false;
};
</script>